$(function () {
    $.ajax({
        url:"/user/findCategory",
        type:"PUT",
        success:function (resultInfo) {
            // console.log(resultInfo);
            // console.log(resultInfo.data);
            // console.log(resultInfo.data.length);
            if (resultInfo.flag) {
                // console.log(resultInfo.flag);
                var categoryList = '<li class="nav-active" "><a href="/user/index">首页</a></li>';
                //遍历数据
                for (let i = 0; i < resultInfo.data.length; i++) {
                    var li = '<li><a href="/user/category?no=' + resultInfo.data[i].no + '">' + resultInfo.data[i].name + '</a></li>';
                    categoryList += li;
                }
                //再在页面展示
                $("#category").html(categoryList);
            }
        },
        error:function (e) {
            console.log("头部出现了错误");
        }
    });



});
//搜寻时候
$("#search_button").click(function () {
    console.log("点了有效果吗？");
    var waresName = $("#search_input").text();
    console.log(waresName);
    // location.href = "/user/category/search?waresName="+waresName;
    // searchWares(1,waresName);
});
function toSearch() {
    // console.log("点了有效果吗？");
    // var waresName = $("#search_input").text();
    var waresName = window.document.getElementById("search_input").value;
    // console.log(waresName);
    location.href = "/user/category/search?waresName="+waresName;
}


function searchWares(currentPage,waresName) {
    $.ajax({
        url:"/user/category/searchWares",
        type:"PUT",
        data:{
            currentPage:currentPage,
            waresName:waresName
        },
        success:function (resultInfo) {
            if(resultInfo.flag){

            }else {
                console.log("大驾光临有失远迎啊")
            }
        }
    });


}


function seeYou() {
    $.ajax({
        url:"/user/logOut",
        type: "DELETE",
        success:function (data) {
            alert(data);
            //刷新页面
            // location.reload();
            //去首页
            window.location.href="/user/index";
        }
    })
}
